home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
FIX_DESK
/
SOURCE
/
BUNDLES.C
< prev
next >
Wrap
C/C++ Source or Header
|
1988-09-07
|
3KB
|
155 lines
#include <MacTypes.h>
#include <ResourceMgr.h>
#include "fix.h"
/* Local types. */
typedef struct bndl_node {
struct bndl_node *next;
int bndl_id;
long bndl_type;
Handle bndl_resource;
} bndl_node, *bndl_ptr;
static bndl_ptr bndl_table;
/* Local prototypes. */
long bundle_type(Handle hand);
void insert_bndl(int number, Handle hand);
void kill_related(long type, Handle hand);
/* Insert an bundle record into the list. */
static void insert_bndl(number, hand)
int number;
Handle hand;
{
register bndl_ptr temp = (bndl_ptr) NewPtr((long) sizeof(bndl_node));
temp->next = bndl_table; /* Insert at */
temp->bndl_id = number; /* beginning of */
temp->bndl_type = bundle_type(hand); /* list... */
temp->bndl_resource = hand;
bndl_table = temp;
}
/* Remove a bundle record from the list. */
void remove_bndl(type)
register long type;
{
register bndl_ptr temp, prev;
temp = bndl_table;
prev = NIL;
while ((temp) && (temp->bndl_type != type)) {
prev = temp;
temp = temp->next;
}
if (temp) { /* Found it... */
if (!prev) /* Unlink from chain... */
bndl_table = temp->next;
else
prev->next = temp->next;
DisposPtr(temp);
}
}
/* Find the owner of a bundle. */
static long bundle_type(hand)
Handle hand;
{
return (**((long **)hand));
}
/* Perform initial bundle processing. */
void pre_bundle_processing()
{
register Handle hand;
register int i, count;
int number;
long blob;
char blob2[256];
/* Empty the bundle list. */
bndl_count = 0;
bndl_table = NIL;
/* Insert all BNDL resources into the list. */
count = Count1Resources('BNDL'); /* Insert all BNDL */
for (i=1; i<=count; i++) { /* resources into the */
hand = Get1IndResource('BNDL',i); /* list... */
HNoPurge(hand);
GetResInfo(hand, &number, &blob, &blob2);
insert_bndl(number, hand);
}
}
/* Perform final bundle processing. */
void post_bundle_processing()
{
register bndl_ptr temp, temp2;
/* Kill all related resources, then each bundle. */
temp = bndl_table;
while (temp) {
bndl_count++;
#ifndef TEST_MODE
kill_related(temp->bndl_type, temp->bndl_resource);
RmveResource(temp->bndl_resource);
DisposHandle(temp->bndl_resource);
#endif TEST_MODE
temp2 = temp;
temp = temp->next;
DisposPtr(temp2);
}
}
#ifndef TEST_MODE
/* Remove resources referred to by a bundle. */
static void kill_related(type, hand)
long type;
Handle hand;
{
register int *bundle; /* Pointer to bundle so far... */
register int res_id, /* Resource ID number. */
num_types, /* Number of resource types. */
num_this; /* Number of resources of this type. */
register long this_type; /* Type of these resources. */
HLock(hand);
bundle = (int *) *hand;
bundle += 2; /* Skip to signature ID #. */
res_id = *(bundle++);
kill_resource(type, res_id);
num_types = *(bundle++);
while (num_types >= 0) { /* For each type... */
--num_types;
this_type = *((long *) bundle); /* Get the type... */
bundle += 2;
num_this = *(bundle++); /* Count of this type... */
while (num_this >= 0) { /* For each resource... */
--num_this; /* Skip local ID... */
bundle++; /* Get res. ID... */
res_id = *(bundle++); /* and remove it! */
kill_resource(this_type,res_id);
}
}
HUnlock(hand);
}
#endif TEST_MODE